package com.dime.physical.controller;

import com.dime.physical.domain.DimePhysicalregister;
import com.dime.physical.domain.dto.SearchPhysicalregister;
import com.dime.physical.mapper.DimePhysicalregisterMapper;
import com.dime.physical.service.impl.DimeMainCheckServiceImpl;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/MainCheckExamine")
public class DimeMainCheckExamineController extends BaseController {


    @Autowired
    private DimePhysicalregisterMapper dimePhysicalregisterMapper;


    @Autowired
    private DimeMainCheckServiceImpl dimeMainCheckService;


    // @RequiresPermissions("physical:MainCheckExamine:list")
    @GetMapping("/list")
    public AjaxResult list(SearchPhysicalregister searchPhysicalregister) {

        List<DimePhysicalregister> list = dimePhysicalregisterMapper.searchMainCheckExamineList(searchPhysicalregister);
        return success(list);
    }

    // @RequiresPermissions("physical:MainCheckExamine:reportlist")
    @PostMapping("/reportlist")
    public AjaxResult reportlist(@RequestBody SearchPhysicalregister searchPhysicalregister) {

        List<DimePhysicalregister> list = dimePhysicalregisterMapper.searchMainCheckExamineReportList(searchPhysicalregister);
        return success(list);
    }


    @RequiresPermissions("physical:MainCheckExamine:examin")
    @PostMapping("/examin")
    public AjaxResult MainCheckExamin(@RequestBody SearchPhysicalregister searchPhysicalregister) {

        if (Integer.parseInt(searchPhysicalregister.getCompletStatus()) < 1) {
            return success("该人员主检未完成！");
        }

        return success(dimeMainCheckService.MainCheckExamine(searchPhysicalregister));
    }


    @RequiresPermissions("physical:MainCheckExamine:Unexamin")
    @PostMapping("/Unexamin")
    public AjaxResult MainCheckUnExamin(@RequestBody SearchPhysicalregister searchPhysicalregister) {

        if (Integer.parseInt(searchPhysicalregister.getCompletStatus()) != 3) {
            return success("该人员主检未审核！");
        }

        return success(dimeMainCheckService.MainCheckUnExamine(searchPhysicalregister));
    }


    @PostMapping("/RevokeMaincheck")
    public AjaxResult RevokeMaincheck(@RequestBody DimePhysicalregister dimePhysicalregister) {


        if (Integer.parseInt(dimePhysicalregister.getCompletStatus()) < 1) {
            return error("该人员主检未完成！");
        }

        dimePhysicalregister.setMainCheckRevoke((dimePhysicalregister.getMainCheckRevoke() == null ? 0 : dimePhysicalregister.getMainCheckRevoke())+ 1);

        return success(dimeMainCheckService.RevokeMaincheck(dimePhysicalregister));
    }
}
